package com.coolingme.springcloud.sentinel;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.stereotype.Service;

/**
 * @author wangyue
 * @date 2022/10/18 11:30
 */
@Service
public class SentinelService {

    /**
     * 同时配置blockHandler和fallback 以blockHandler为主
     *
     * @author wangyue
     * @date 2022/10/18 11:33
     */
    @SentinelResource(value = "say", blockHandler = "sayBlockHandler", fallback = "sayFallback")
    public String say(String name) {
        return "Hello " + name;
    }

    public String sayBlockHandler(String name, BlockException e) {
        e.printStackTrace();
        return "被限流了 " + name;
    }

    public String sayFallback(String name) {
        return "被降级了 " + name;
    }

}
